<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('承办部门T')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            承办单位：<input type="text" name="sbdeptName"/>
                        </li>
                        <li>
                            办理性质：<input type="text" name="sortName"/>
                            <input type="hidden" name="wfId" id="wfId" th:value="${wfId}"/>
                            <input type="hidden" name="telId" id="telId" th:value="${telId}"/>
                            <input type="hidden" name="sbId" id="sbId" th:value="${sbId}"/>
                            <input type="hidden" name="resendType" id="resendType" th:value="${param.resendType}"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm " id="toolbar" role="group">
            <a class="btn btn-success" onclick="sendDept()">
                <i class="fa fa-plus"></i> 新增
            </a>
<!--            <a class="btn btn-primary multiple disabled" onclick="OnQxListEditWin()">-->
<!--                <i class="fa fa-edit"></i> 修改-->
<!--            </a>-->
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-primary multiple disabled" onclick="returnBack()">
                <i class="fa fa-edit"></i> 撤回
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/common/js/common.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "system/mTelWF";
    var send = ctx + "system/sendBack";
    $(function () {
        var options = {
            url: prefix + "/rCity/sendBackListJson",
            sortName: "pkId",
            sortOrder: "desc",
            uniqueId: "myPkVal",
            updateUrl: prefix + "/rCity/mmReturnReason/{id}",
            removeUrl: prefix + "/rCity/removeSendBack",
            modalName: "拟派工单",
            fixedColumns: true,
            fixedNumber: 2,
            fixedRightNumber: 1,
            columns: [{
                checkbox: true
            },
                {field: 'myPkVal', title: 'pkid', visible: false},
                {field: 'WfId', title: 'WfId', visible: false},
                {field: 'SeqName', title: '交办次序', align: 'center', sortable: true},
                {field: 'SortName', title: '办理性质', align: 'center', sortable: true},
                {field: 'DealName', title: '办理方式', align: 'center', sortable: true},
                {field: 'SBDeptName', title: '承办单位', align: 'center', sortable: true},
                {field: 'SendDesc', title: '办理要求', visible: false},
                {field: 'SDeptName', title: '派发单位', visible: false},
                {field: 'backLimit', title: '要求期限', align: 'center', width: 80},
                {field: 'SUserName', title: '派发人', visible: false},
                {field: 'sendTime', title: '派发时间', align: 'center', width: 80},
                {
                    field: 'chgState', title: '办理情况', align: 'center', formatter: function (value, row, index) {
                        return fmtSBSendState(value, row, index);
                    }
                },
                {field: 'getTime', title: '签收时间', align: 'center', width: 80},
                {field: 'GetPerson', title: '签收联系人', align: 'center', sortable: true},
                {field: 'BUserName', title: '回复人', align: 'center'},
                {field: 'backTime', title: '回复时间', align: 'center', width: 80},
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="OnQxListEditWin(' + row.myPkVal + ')"><i class="fa fa-edit"></i>&nbsp;编辑</a>&nbsp;&nbsp;');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="sendBackDetail(' + row.myPkVal + ')"><i class="fa fa-info"></i>&nbsp;回复情况</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    let wfId = $('#wfId').val();
    let telId = $('#telId').val();
    let sbId = $('#sbId').val();
    let resendType = $('#resendType').val();
    let pid=[[${pid==null?0:pid}]];

    function sendDept() {
        var url = prefix + "/rCity/sendDept/" + wfId+"?sbId="+sbId+'&resendType='+resendType+"&pid="+pid;
        var config = {
            id: 'dlSendToSon',
            title: '拟办部门',
            width: '85%',
            height: '80%',
            url: url,
            callBack: function (index, layero) {
                var iframeWin = layero.find('iframe')[0];
                var curIframe = parent.document.getElementById(window.name);
                beforeSend();
                iframeWin.contentWindow.submitHandler(curIframe);
                completeSend();
            }
        };
        $.modal.openOptions(config);
    }

    //修改派单
    function OnQxListEditWin(pkId) {
        if (!pkId) {
            let row = $("#bootstrap-table").bootstrapTable('getSelections');
            pkId = row[0].myPkVal;
        }
        var url = prefix+'/rCity/sendDeptEdit/'+wfId +'/'+pkId;
        var width = '70%';
        var config = {
            id: 'dlSendToSon',
            title: '拟办部门',
            width: width,
            url: url,
            callBack: function (index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler();
                $.table.refresh();
            }
        };
        $.modal.openOptions(config);
    }

    //撤回派单
    function returnBack(title) {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        if (title == null) {
            title = "确认要撤回选中的" + rows.length + "条数据吗?"
        }
        $.modal.confirm(title, function () {
            let row = $("#bootstrap-table").bootstrapTable('getSelections');
            if (row[0].isGoBack == 1){
                $.modal.alertWarning("此工单不允许退回");
                return false;
            }
            var url = prefix + '/rCity/returnBack/' + row[0].myPkVal;
            $.operate.submit(url, "post", "json");
        });
    }

    //查看办理情况详情
    function sendBackDetail(sbid) {
        var url = "system/mTelWF/forShow/dealDetail/"+sbid;
        var width = '70%';
        var height = '74%';
        var config = {
            title: '办理情况-详情',
            width: width,
            height : height,
            url: url,
            btn:['关闭'],
            skin: 'layui-layer-gray',
            yes: function (index, layero) {
                $.modal.close(index);
            }
        };
        $.modal.openOptions(config);
    }
</script>
</body>
</html>